﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;

namespace WebApplication2.Instrument
{
    public class PostAndCode
    {
        public static string GerCode()
        {
            string code = "";
            string num1 = (new Random().Next(500, 1000)).ToString();
            string num2 = (new Random().Next(100, 500)).ToString();
            code = num1 + num2;
            HttpContext.Current.Session["emailCode"] = code;
            return num1 + num2;
        }

        public static void SendPost(string toEmail)
        {
            MailMessage m = new MailMessage();
            m.From = new MailAddress("1270063093@qq.com","汽车百宝箱");
            m.To.Add(toEmail);
            m.Subject = "计算机网络技术_验证码";
            m.Body = "感谢您注册汽车百宝箱，您的验证码为:" + GerCode() + ",\r\n请勿转告他人，感谢配合您的使用！";
            m.SubjectEncoding = System.Text.Encoding.UTF8;
            m.BodyEncoding = System.Text.Encoding.UTF8;

            SmtpClient s = new SmtpClient();
            s.Credentials = new NetworkCredential("1270063093@qq.com", "pfdbzniorepdfidj");
            s.Host = "smtp.qq.com";
            s.Send(m);
        }


    }
}